﻿#ifndef __INTERPOLATIONCURVEDERI_H__
#define __INTERPOLATIONCURVEDERI_H__
#include "Strategy.h"
#include "bsplineCurveAbstract.h"
#include <QMouseEvent>
#include <QGLWidget>
#include <Eigen/Dense>
#include <cmath>

class InterpolateCurveDeri :public QGLWidget, public Strategy {
	Q_OBJECT
public:
	InterpolateCurveDeri(QWidget *parent = 0);
	~InterpolateCurveDeri();
	double chordLength(const Point3d & a, const Point3d &b);
	void jsonReader(std::string);
	void genPoints(std::string);
	int findSpan(int numOfCtlPoint, int order, double u, const std::vector<double> &U);
	void basisFuns(int i, double u, int order, const std::vector<double> &U, std::vector<double> &base);
	void curvePoint(int n, int p, const std::vector<double>&U, std::vector<Point3d>&P, double u, Point3d &C);
	void resizeGL(int width, int height);
	void initializeGL();

	void globalCurveInterp(const std::vector<Point3d> &Q, int p, int &m, std::vector<double> &U, std::vector<Point3d> &ctlPts);
protected:
	//void paintEvent(QPaintEvent *);
	void paintGL();//绘制opengl图形
	void mousePressEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
	void wheelEvent(QWheelEvent *event);
private:
	//SweptVolumeConfig SVCfg;// 两条 nurbs 曲线
	int p;
	std::vector<Point3d> Q;//要拟合的点
	Eigen::Vector3f D0;
	Eigen::Vector3f Dn;// 要拟合的两个方向向量
	std::vector<Point3d> curvePoints;//曲线上的点
	std::vector<Point3d> ctlPts;//曲线的控制点
	int curvePointNum;
	int flag;//判断选中的是哪一个控制点
	QPointF lastPos;//因为是平面，所以只能获得（x,y)二维坐标
	double rotationX;
	double rotationY;
	double rotationZ;
	double times;
};

#endif